USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcAgregarDetalleAlquiler]    Script Date: 11/18/2012 15:32:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcAgregarDetalleAlquiler]
	-- Add the parameters for the stored procedure here
	@Tipo_Moneda as varchar(50),
	@TipoPago as varchar(50),
	@MontoPagareses as money,
	@CantidadDeposito as int,
	@Id_Propiedad as int
	
	AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into DetallesPagoAlquiler(Tipo_Moneda, TipoPago, MontoPagareses, CantidadDeposito)
	VALUES(@Tipo_Moneda,@TipoPago,@MontoPagareses, @CantidadDeposito)
	update Propiedades set Id_Detalle_AL = (select TOP 1 Id_Detalle_Alquiler from DetallesPagoAlquiler ORDER BY CreatedDate DESC) where Id_Propiedad = @Id_Propiedad
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcAgregarDetalleVenta]    Script Date: 11/18/2012 15:32:38 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcAgregarDetalleVenta] 
	-- Add the parameters for the stored procedure here
	@TipoMoneda as varchar(50),
	@Valor as money,
	@Id_Propiedad as int
	AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into DetallesPagosVenta(TipoMoneda, Valor) VALUES (@TipoMoneda, @Valor)
	update Propiedades set Id_Detalle_Ve = (select TOP 1 Id_DetallesPagosVenta from DetallesPagosVenta ORDER BY CreateDate DESC) Where Id_Propiedad = @Id_Propiedad
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcAgregarDireccion]    Script Date: 11/18/2012 15:32:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcAgregarDireccion]
	-- Add the parameters for the stored procedure here
	@Direccion as varchar(50),
	@Id_Sector as int,
	@Latitud as numeric(10,10),
	@Longitud as numeric(10,10),
	@Id_Propiedad as int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into Direcciones(Direccion, Id_Sector, Latitud, Longitud)
	VALUES(@Direccion, @Id_Sector, @Latitud, @Longitud)
	update Propiedades set ID_Direccion = (select TOP 1 ID_Direccion from Direcciones ORDER BY Id_Direccion DESC) Where Id_Propiedad = @Id_Propiedad
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcGuardarNuevaCasa]    Script Date: 11/18/2012 15:32:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcGuardarNuevaCasa] 
	-- Add the parameters for the stored procedure here
	@Id_Propiedad as int,
	@Dormitorios as int,
	@CuartoServicio_ as int,
	@MetrosSolares as int,
	@Parqueos as int,
	@MetrosConstruccion as int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into CaracteristicaPropiedades(Nombre, Cantidad, Id_Propiedad)
	SELECT 'Dormitorios', @Dormitorios, @Id_Propiedad
	UNION ALL 
	SELECT 'CuartoServicio_', @CuartoServicio_, @Id_Propiedad
	UNION ALL
	SELECT 'MetrosSolares', @MetrosSolares, @Id_Propiedad
	UNION ALL
	SELECT 'Parqueos', @Parqueos, @Id_Propiedad
	UNION ALL
	SELECT 'MetrosConstruccion', @MetrosConstruccion, @Id_Propiedad
	
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcGuardarNuevaPropiedad]    Script Date: 11/18/2012 15:33:07 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcGuardarNuevaPropiedad]
	-- Add the parameters for the stored procedure here
	@Categoria as int,
	@ContactoVenta as int,
	@ContactoAlquiler as int,
	@descripcion as varchar(MAX),
	@arrendador as int
	AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into Propiedades(Id_Categoria, Id_Arrendador, Id_Ve_Contacto, Id_Al_Contacto, Id_Ve_Stat, Id_AL_Stat, Descripcion)
	VALUES(@Categoria, @arrendador,@ContactoVenta, @ContactoAlquiler, '4','4',@descripcion);
	select TOP 1 Id_Propiedad from Propiedades where Id_Categoria = @Categoria and Id_Arrendador = @arrendador and Id_Al_Contacto = @ContactoAlquiler and Id_Ve_Contacto = @ContactoVenta and Descripcion = @descripcion ORDER BY CreatedDate DESC;
	
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcGuardarNuevoApartamento]    Script Date: 11/18/2012 15:33:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcGuardarNuevoApartamento] 
	-- Add the parameters for the stored procedure here
	@Id_Propiedad as int,
	@Dormitorios as int,
	@CuartoServicio_ as int,
	@Acensor_ as int,
	@Parqueos as int,
	@MetrosCuadrados as int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into CaracteristicaPropiedades(Nombre, Cantidad, Id_Propiedad)
	SELECT 'Dormitorios', @Dormitorios, @Id_Propiedad
	UNION ALL 
	SELECT 'CuartoServicio_', @CuartoServicio_, @Id_Propiedad
	UNION ALL
	SELECT 'Acensor_', @Acensor_, @Id_Propiedad
	UNION ALL
	SELECT 'Parqueos', @Parqueos, @Id_Propiedad
	UNION ALL
	SELECT 'MetrosCuadrados', @MetrosCuadrados, @Id_Propiedad
	
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcGuardarNuevoSolar]    Script Date: 11/18/2012 15:33:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcGuardarNuevoSolar] 
	-- Add the parameters for the stored procedure here
	@Id_Propiedad as int,
	@MetrosCuadrados as int,
	@CostoPorMetroCuadrado as int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	insert into CaracteristicaPropiedades(Nombre, Cantidad, Id_Propiedad)
	SELECT 'MetrosCuadrados', @MetrosCuadrados, @Id_Propiedad
	UNION ALL 
	SELECT 'CostoPorMetroCuadrado', @CostoPorMetroCuadrado, @Id_Propiedad
	
END

GO

